import { contextBridge, ipcRenderer } from 'electron'
import type { ProgressInfo } from 'electron-updater'

contextBridge.exposeInMainWorld('main', {
  onDownProgress: (callback) => {
    ipcRenderer.on('down:progress', (_event, progressInfo: ProgressInfo) => {
      callback(progressInfo)
    })
  },
  getUpdateInfo: () => {
    return ipcRenderer.invoke('update:info')
  },
  confirmDown: () => ipcRenderer.send('start:down'),
  openDialog: (options) => ipcRenderer.invoke('open:dialog', options),
  quitAndInstall: () => ipcRenderer.send('quit:and:install')
})
